package pluginMain;

import java.util.List;
import java.util.logging.Logger;

import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockFromToEvent;

public class FlowLimit extends JavaPlugin implements Listener {
	public final String PLUGIN_NAME = "Flow Limiter";
	public final Logger CONSOLE_LOGGER = this.getLogger();
	public boolean DEBUGFLAG;
	public List<String> ENABLE_WORLD;
	
	public void DEBUGLOG(String msg) {
		if(!DEBUGFLAG) return;
		CONSOLE_LOGGER.info(msg);
	}
	public void LOGCONSOLE(String msg) {
		CONSOLE_LOGGER.info(msg);
	}

	@Override
	public void onEnable() {
		this.saveDefaultConfig();
		this.getServer().getPluginManager().registerEvents(this, this);
		DEBUGFLAG = this.getConfig().getBoolean("Debug");
		ENABLE_WORLD = this.getConfig().getStringList("EnableWorld");
		LOGCONSOLE(PLUGIN_NAME + " has been started.");
	}

	@Override
	public void onDisable() {
		LOGCONSOLE(PLUGIN_NAME + " has been disabled.");

	}

	@EventHandler
	public void onWaterFlow(BlockFromToEvent event) {
		if (ENABLE_WORLD.contains(event.getBlock().getWorld().getName())) {
			DEBUGLOG("BLOACK SPAREAD CATCHED: " + event.getEventName());
			DEBUGLOG("CASTLE WORLD: "
					+ event.getBlock().getWorld().getName());
			if (event.getBlock().isLiquid()) {
				DEBUGLOG("LIQUID DEATTACH");
				DEBUGLOG("CANCELED");
				event.setCancelled(true);
				return;
			}
		}

	}
}
